package IC.SemanticChecks;

/**
 * SemanticError Exception
 */
public class SemanticError extends Exception {
	
	private static final long serialVersionUID = 1L;
	private static SemanticError Catch=null;
	
	private SemanticErrorType Type = null;
	private int ln;

	//C'tor
	public SemanticError(SemanticErrorType Type, int ln) {
		super(Type.getMsg());
		this.Type = Type;
		this.ln = ln;
	}

	public String getMessage() {
		return "semantic error at line "+ ln +": " + Type.toString();
	}
	
	public static void handle(SemanticErrorType semanticErrorType, int lineNumber) {
		Catch=new SemanticError(semanticErrorType,lineNumber);
	}
	
	public static boolean hasError() {
		return Catch!=null;
	}
	
	public static void throwError() throws SemanticError {
		if (hasError())
			throw Catch;
	}
	 
}
